package cn.signalpha.modules.shop.controller.seller;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.modules.shop.entity.GoodsCategory;
import cn.signalpha.modules.shop.service.GoodsCategoryService;
import cn.signalpha.modules.shop.vo.GoodsCategoryVO;
import cn.signalpha.modules.shop.wrapper.GoodsCategoryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/sys-seller/goods/category")
@Api(value = "商品分类", tags = "商品分类")
public class SpiGoodsCategoryController extends BaseController {

	private final GoodsCategoryService goodsCategoryService;

	@GetMapping("/list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "parentId", value = "上级id", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "分类名称", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "level", value = "分类等级", paramType = "query", dataType = "string"),
	})
	@ApiOperation(value = "列表", notes = "")
	public R<List<GoodsCategory>> list(@ApiIgnore @RequestParam Map<String, Object> params) {
		return R.data(goodsCategoryService.list(Condition.getQueryWrapper(params, GoodsCategory.class)));
	}

	@GetMapping("/lazy-list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "parentId", value = "上级id", paramType = "query", dataType = "string"),
		@ApiImplicitParam(name = "name", value = "分类名称", paramType = "query", dataType = "string"),
	})
	@ApiOperation(value = "懒加载列表", notes = "")
	public R<List<GoodsCategoryVO>> lazyList(Long parentId, @ApiIgnore @RequestParam Map<String, Object> params) {
		return R.data(GoodsCategoryWrapper.build().listNodeLazyVO(goodsCategoryService.lazyList(parentId, params)));
	}

	@GetMapping("/tree")
	@ApiOperation(value = "树形结构", notes = "")
	public R<List<GoodsCategoryVO>> tree(@ApiIgnore @RequestParam Map<String, Object> params) {
		return R.data(goodsCategoryService.tree(params));
	}

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<GoodsCategoryVO> info(@RequestParam Long id) {
		return R.data(GoodsCategoryWrapper.build().entityVO(goodsCategoryService.getById(id)));
	}

}
